import java.util.HashMap;
import java.util.Map;

/**
 * Simple demo to test Pinyin conversion functionality
 */
public class PinyinDemo {

    private static final Map<Character, String> PINYIN_MAP = new HashMap<>();

    static {
        // Initialize common Chinese characters using Unicode
        PINYIN_MAP.put('\u5f20', "zhang");
        PINYIN_MAP.put('\u4e09', "san");
        PINYIN_MAP.put('\u674e', "li");
        PINYIN_MAP.put('\u56db', "si");
        PINYIN_MAP.put('\u738b', "wang");
        PINYIN_MAP.put('\u4e94', "wu");
        PINYIN_MAP.put('\u8d75', "zhao");
        PINYIN_MAP.put('\u516d', "liu");
        PINYIN_MAP.put('\u9648', "chen");
        PINYIN_MAP.put('\u5c0f', "xiao");
        PINYIN_MAP.put('\u660e', "ming");
        PINYIN_MAP.put('\u7ea2', "hong");
        PINYIN_MAP.put('\u7f8e', "mei");
        PINYIN_MAP.put('\u4e3d', "li");
    }
    
    public static String convertToPinyin(String chineseName) {
        if (chineseName == null || chineseName.trim().isEmpty()) {
            return "";
        }

        StringBuilder pinyin = new StringBuilder();
        for (char c : chineseName.toCharArray()) {
            if (PINYIN_MAP.containsKey(c)) {
                pinyin.append(PINYIN_MAP.get(c));
            } else if (Character.isLetter(c)) {
                pinyin.append(Character.toLowerCase(c));
            }
        }

        return pinyin.toString();
    }
    
    public static String generateUsername(String studentName, String classCode) {
        String pinyin = convertToPinyin(studentName);
        if (pinyin.isEmpty()) {
            pinyin = "student";
        }
        
        if (classCode != null && !classCode.trim().isEmpty()) {
            return pinyin + classCode;
        } else {
            return pinyin;
        }
    }
    
    public static void main(String[] args) {
        System.out.println("=== Student Account Creation Demo ===");
        
        // Test cases using Unicode strings
        String[][] testCases = {
            {"\u5f20\u4e09", "2024"},
            {"\u674e\u56db", "01"},
            {"\u738b\u4e94", "2024"},
            {"\u8d75\u516d", "01"},
            {"\u9648\u5c0f\u660e", "2024"},
            {"\u674e\u7f8e\u4e3d", "01"}
        };
        
        System.out.println("Student Name | Class Code | Generated Username | Password");
        System.out.println("-------------|------------|-------------------|----------");
        
        for (String[] testCase : testCases) {
            String studentName = testCase[0];
            String classCode = testCase[1];
            String username = generateUsername(studentName, classCode);
            String password = "88888888"; // Default password
            
            System.out.printf("%-12s | %-10s | %-17s | %s%n", 
                studentName, classCode, username, password);
        }
        
        System.out.println("\n=== Test Edge Cases ===");
        
        // Edge cases
        System.out.println("Empty name + class 2024: " + generateUsername("", "2024"));
        System.out.println("Null name + class 2024: " + generateUsername(null, "2024"));
        System.out.println("ZhangSan + empty class: " + generateUsername("\u5f20\u4e09", ""));
        System.out.println("ZhangSan + null class: " + generateUsername("\u5f20\u4e09", null));
        System.out.println("Mixed ZhangABC + 2024: " + generateUsername("\u5f20ABC", "2024"));
        
        System.out.println("\n=== Demo Complete ===");
    }
}
